home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1415 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  36 lines

  1. Path: locutus.rchland.ibm.com!usenet
  2. From: pstaite@vnet.ibm.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Time countdown
  5. Date: 10 Jan 1996 21:44:30 GMT
  6. Organization: IBM OS/2 Device Driver Development  Rochester, MN
  7. Message-ID: <4d1bvu$qn6@locutus.rchland.ibm.com>
  8. References: <723_9601092245@medtechnet.com>
  9. Reply-To: pstaite@vnet.ibm.com
  10. NNTP-Posting-Host: warpone.rchland.ibm.com
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <723_9601092245@medtechnet.com>, Tony.Johnston@dreams.medtechnet.com (Tony Johnston) writes:
  14. >  I am using Borland C++ 4.00.   I am writing a program that I would like to
  15. >have a 10 second delay in it.  I would like it to be a visual countdown from
  16. >10 to 1 and I have no idea how to do this. Can anyone offer some sample code
  17. >on how this is done?
  18.  
  19. #include<stdlib.h>
  20.  
  21.  
  22.  
  23. for( int i = 10 ; i > 0 ; --i ) {
  24.     // update display with value of i
  25.     sleep( 1 ); }
  26.  
  27. Should give you an approximation.  If you want to make sure you don't 
  28. miss a second. (sleep only guarantees you'll sleep for at least that 
  29. long)  You could use delay() and check the time() more often than once a
  30. second, and only update the display when the second count changes.
  31.  
  32.  
  33. Phil Staite, team OS/2
  34. internet: pstaite@vnet.ibm.com  internal: pstaite@rchland
  35.  
  36.